package com.m7788.screen;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

import com.m7788.util.AppUtil;
import com.m7788.util.Constant;
import com.m7788.view.UmengBaseActivity;

public class GuideScreen extends UmengBaseActivity {
	/** Called when the activity is first created. */
	private ViewPager viewPaper;
	private ArrayList<View> pageViews;  

	private Button btn_start;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.guide_screen);
		LayoutInflater inflater = getLayoutInflater();
		pageViews = new ArrayList<View>();
		View view1 = inflater.inflate(R.layout.guide_screen_son1, null);
		View view2 = inflater.inflate(R.layout.guide_screen_son2, null);
		View view3 = inflater.inflate(R.layout.guide_screen_son3, null);
		pageViews.add(view1);  
		pageViews.add(view2);  
		pageViews.add(view3);  
		viewPaper = (ViewPager)findViewById(R.id.guidePages);
		btn_start = (Button)view3.findViewById(R.id.gs_btn_start);
		btn_start.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				AppUtil.saveRecord(GuideScreen.this, Constant.FIRSTSTART,"true");
				Intent intent = new Intent (GuideScreen.this,LoginScreen.class);			
				startActivity(intent);			
				GuideScreen.this.finish();				
			}
			
		});

		viewPaper.setAdapter(new GuidePageAdapter());
	}
	class GuidePageAdapter extends PagerAdapter {  

		@Override  
		public int getCount() {  
			return pageViews.size();  
		}  

		@Override  
		public boolean isViewFromObject(View arg0, Object arg1) {  
			return arg0 == arg1;  
		}  

		@Override  
		public int getItemPosition(Object object) {  
			return super.getItemPosition(object);  
		}  

		@Override  
		public void destroyItem(View arg0, int arg1, Object arg2) {  
			((ViewPager) arg0).removeView(pageViews.get(arg1));  
		}  

		@Override  
		public Object instantiateItem(View arg0, int arg1) {  
			((ViewPager) arg0).addView(pageViews.get(arg1));  
			return pageViews.get(arg1);  
		}  

		@Override  
		public void restoreState(Parcelable arg0, ClassLoader arg1) {  

		}  

		@Override  
		public Parcelable saveState() {  
			return null;  
		}  

		@Override  
		public void startUpdate(View arg0) {  

		}  

		@Override  
		public void finishUpdate(View arg0) {  

		}  
	} 


}